package com.dayang.nm.ugcaudit.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.dayang.baseplatform.model.CommonDisplay;
import com.dayang.baseplatform.model.UgcTask;
import com.dayang.baseplatform.service.ugcaudit.AuditListService;

public class AuditListAction extends BaseAction {
	
	@Override
	public String create(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		return null;
	}

	@Override
	public String delete(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

	@Override
	public String update(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		UgcTask ugcTask = (UgcTask)this.getObjectFromRequest(request, "task", UgcTask.class);
		String destIdListStr = request.getParameter("destIdArray");
		JSONArray destIdListJson = JSONArray.fromString(destIdListStr);
		List destList = JSONArray.toList(destIdListJson);
		String isEditStr = request.getParameter("isEdit");
		boolean isEdit = Boolean.parseBoolean(isEditStr);
		String classId = request.getParameter("classId");
		String memo = request.getParameter("memo");
		
		AuditListService auditListService = new AuditListService();
		boolean suc = auditListService.update(ugcTask,classId,isEdit,memo,destList);
		ugcTask.getTaskStatus();
		Map	mp = new HashMap();
		mp.put("success", suc);
		
		JSONObject object = JSONObject.fromBean(mp);
		String jsonStr = object.toString();
		
		return jsonStr.toString();
	}

	@Override
	public String read(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String listType = request.getParameter("listType");
//		String startStr = request.getParameter("start");
//		String countStr = request.getParameter("count");
		
//		int start = Integer.parseInt(startStr);
//		int count = Integer.parseInt(countStr);
		
		
		AuditListService auditListService = new AuditListService();
		CommonDisplay commonDisplay = auditListService.read(listType,0,10);
		
		JSONObject object = JSONObject.fromBean(commonDisplay);
		String jsonStr = object.toString();
		
		return jsonStr;
	}
	
	//tomato princess...
	
}
